#!/usr/bin/env ruby

require 'benchmark'

module RubyProfile

   def RubyProfile.iters 
      5000000
   end

   def RubyProfile.times_sum(n)
      s = 0
      n.times { |i| s += (i+1) }
      return s
   end

   def RubyProfile.inject_sum(n)
      (0..n).inject { |x,y| x + y }
   end

   def RubyProfile.run_benchmarks 
      n = RubyProfile.iters
      Benchmark.bmbm do |bm|
	 bm.report('times_sum:') { RubyProfile.times_sum(n) }
	 bm.report('inject_sum:') { RubyProfile.inject_sum(n) }
      end
   end

end

RubyProfile.run_benchmarks
